package com.szcinda.service.dto.analysis;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
public class CargoDataDto implements Serializable {
    private String clientName;


    private String goodsName;
    private Double goodsWeight;

    private List<Item> items = new ArrayList<>();

    public void addItem(String goodsName, Double goodsWeight){
        if(goodsWeight == null){
            return;
        }
        Item record = items.stream().filter(item -> item.goodsName.equals(goodsName))
                .findFirst().orElse(null);
        if(record == null){
            record = new Item();
            record.setGoodsName(goodsName);
            record.setGoodsWeight(goodsWeight);
            items.add(record);
        }else{
            record.setGoodsWeight(record.getGoodsWeight()+goodsWeight);
        }
    }

    @Data
    public static class Item implements Serializable{
        private String goodsName;
        private Double goodsWeight;
    }
}
